package rsj.service;

import com.rlyy.aibase.utils.base.MapNode;
import common.util.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rsj.dao.ProdCollDao;
import rsj.dao.ProductDao;

public class ProdCollService {
    private static final Logger logger = LoggerFactory.getLogger(ProdCollService.class);
    private static final ProdCollService instance = new ProdCollService();
    public static ProdCollService getInstance() {
        return instance;
    }

    private static final ProdCollDao prodCollDao = ProdCollDao.getInstance();
    private static final ProductDao productDao = ProductDao.getInstance();

    public void save(MapNode data) {
        checkParams(data);
        MapNode mapNode = productDao.getById(data.getValue("Prod_Id"));
        String prodName = mapNode.getValue("Prod_Name");

        prodCollDao.insert(data, prodName);
    }

    private void checkParams(MapNode data) {
        Assert.isNotBlank(data.getValue("Org_Id"), "机构Id不能为空！");//Org_Id/机构Id
        Assert.isNotBlank(data.getValue("Prod_Id"), "产品ID不能为空！");//Prod_Id/产品ID
        Assert.isTrue(data.getValue("Coll_Status").equals("0") || data.getValue("Coll_Status").equals("1"), "收藏状态只能为0或者1！");
    }
}
